package main

import "fmt"

// 自定义错误

func main() {
	area, err := rectArea(-5, 5)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(area)
}

type rectangleError struct {
	msg   string
	len   float64
	width float64
}

func (r *rectangleError) Error() string {
	return r.msg
}

func (r *rectangleError) lenNegative() bool {
	return r.len <= 0
}

func (r *rectangleError) widthNegative() bool {
	return r.len <= 0
}

func rectArea(len, width float64) (float64, error) {
	if len < 0 {
		return 0, &rectangleError{len: len, width: width, msg: "len illegal"}
	}
	return 0, nil
}
